<template>
    <div>
        <avue-form ref="form" v-model="obj" :option="option"
                   @reset-change="emptytChange"
                   @submit="submit">

        </avue-form>
    </div>
</template>

<script>
import {uploadPath} from "@/config/env";

export default {
    data() {
        return {
            obj: {},
            treeData: [],
            initSuccess: false,
            defaultData: {
                hierarchy: 2, // 默认加数据
                pid: null,
                name: null,
                code: null,
                prefix: null,
                timeFormat: "yyyyMMdd",
                increment: 0,
                initIncrement: 0,
                incrementLen: 6,
               // lastNo: null,
              //  lastTime: null,
                remarks: null,
            },
        }
    },
    props: {
        uri: {},
        rowData: {},
    },
    computed: {
        option() {
            return {
                // size: "small",
                submitBtn: true,
                emptyBtn: true,
                submitText: '提交',
                emptyText: "关闭",
                column: [
                    {
                        label: '层级 ',
                        prop: 'hierarchy',
                        type: 'radio',
                        labelWidth: 110,
                        dicData: this.dict.get('HIERARCHY'),
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请选择 层级 ",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '父级 ',
                        prop: 'pid',
                        type: 'tree',
                        labelWidth: 110,
                        span: 20,
                        display: true,
                        dicData: this.treeData,
                        props: {
                            value: "id",
                            label: "name",
                            children: "children"
                        },
                        rules: [{
                            required: true,
                            message: "请选择 父级 ",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '标题',
                        prop: 'name',
                        labelWidth: 110,
                        maxlength: 32,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 标题",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: 'code',
                        prop: 'code',
                        display: this.obj.hierarchy === 2,
                        labelWidth: 110,
                        maxlength: 32,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 code",
                            trigger: "blur"
                        }]
                    },
                    {
                        display: this.obj.hierarchy === 2,
                        label: '前缀',
                        prop: 'prefix',
                        labelWidth: 110,
                        maxlength: 8,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请输入 前缀",
                            trigger: "blur"
                        }]
                    },
                    {
                        display: this.obj.hierarchy === 2,
                        label: '时间格式 ',
                        prop: 'timeFormat',
                        type: 'select',
                        labelWidth: 110,
                        filterable: true,
                        dicData: this.dict.get('TIME_FORMAT'),
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请选择 时间格式 ",
                            trigger: "blur"
                        }]
                    },
                    {
                        display: this.obj.hierarchy === 2,
                        label: '初始自增值 ',
                        prop: 'initIncrement',
                        type: 'number',
                        labelWidth: 110,
                        precision: 0,  //保留小数位,
                        min: 0,
                        max: 9999999999999999,
                        step: 1,
                        row: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 初始自增值 ",
                            trigger: "blur"
                        }]
                    }, {
                        display: this.obj.hierarchy === 2,
                        label: '当前自增值 ',
                        prop: 'increment',
                        type: 'number',
                        labelWidth: 110,
                        precision: 0,  //保留小数位,
                        min: 0,
                        max: 9999999999999999,
                        step: 1,
                        row: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 当前自增值 ",
                            trigger: "blur"
                        }]
                    },
                    {
                        display: this.obj.hierarchy === 2,
                        label: '自增值位数',
                        prop: 'incrementLen',
                        type: 'number',
                        labelWidth: 110,
                        precision: 0,  //保留小数位,
                        min: 0,
                        max: 16,
                        step: 1,
                        row: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: "请输入 自增值长度 ",
                            trigger: "blur"
                        }]
                    },
                    {
                        label: '备注',
                        prop: 'remarks',
                        type: 'textarea',
                        labelWidth: 110,
                        maxlength: 256,
                        showWordLimit: true,
                        span: 20,
                        rules: [{
                            required: false,
                            message: "请输入 备注",
                            trigger: "blur"
                        }]
                    },

                ]
            }
        }
    },
    created() {
        this.obj = this.defaultData;
        this.obj.pid = this.rowData.pid;
        if (this.obj.pid === "0") {
            // 加分组
            this.obj.hierarchy = 1;
        }
        this.treeData = JSON.parse(JSON.stringify(this.rowData.pidDic));
        this.initSuccess = true;
    },
    methods: {
        emptytChange() {
            this.$emit('closeDialog', false);
        },
        submit(form, done) {
            this.crud.post(this.uri.info, this.obj).then((res) => {
                console.debug(res);
                if (res.data.code == 200) {
                    this.$emit('closeDialog', true, res.data.data);
                }
                done(form);
            }).catch((err) => {
                console.error(err);
                done(form);
            })
        },
    }
}
</script>
